<?php

if (!defined('IN_ADMIN')) {
    exit('Access Denied');
}

$mpurl	 			= 'admin.php?ac=count_user';

$param['orderby']	=	'level';
$param['ordersc']	=	'desc';
$param['sheetNum']	=	'0';
$param['ac']		=	'count_user';

if ($_GET['query'] == 1 || $_GET['op'] == '1')/*{{{*/
{
	$param	=  $_GET;
	$param['sheetNum']	=	strval($param['sheetNum']);
}/*}}}*/

$param['do']		=	'getAdminCount';
$param['format']	=	'json';
$start   			=   intval($_GET ['start']) > 0 ? intval($_GET ['start']) : 0;
$perpage 			=   intval($_GET ['perpage']) > 0 ? intval($_GET ['perpage']) : 20;
$param['start']		=	$start;
$param['perpage']	=	$perpage;
if (intval($_GET['uid1']) > 0 && intval($_GET['uid2']) && intval($_GET['uid1']) === intval($_GET['uid2'])){
    $index = getHashId($_GET['uid1'], 8);
    $param['sheetNum'] = strval($index);
}
// echo '<pre>';var_dump($param);exit;
$content  =  get_api_content($_SC ['apiurl'], $param);
$content  =  json_decode($content);
$userList =  object_to_array($content->resultData);
for ($i=0;$i<count($userList)-1;$i++)
{
	$result[]	  =		$userList[$i];
}

// 搜索条件
$intkeys = array(
		'uid',
		'level',
		'topicTimes',
		'diaryTimes',
		'commentTimes',
		'meFollowTimes',
		'followMeTimes',
		'likeTimes',
		'registerDate'
);

//条件恢复
$orderbyArr		=	array($param['orderby']	 => " selected");
$orderscArr 	=	array($param['ordersc']  => " selected");
$sheetNumArr 	=	array($param['sheetNum'] => " selected");
$perpageArr 	=	array($param['perpage']  => " selected");
$uidArr 		=	array($param['uid']  	 => " selected");
$levelArr		=	array($param['level1'],$param['level2']);
$uidsArr		=	array($param['uid1'],  $param['uid2']);
$registerDateArr	=	array($param['registerDate1'],  $param['registerDate2']);
$topicTimesArr		=	array($param['topicTimes1'],	$param['topicTimes2']);
$diaryTimesArr		=	array($param['diaryTimes1'],	$param['diaryTimes2']);
$likeTimesArr		=	array($param['likeTimes1'],		$param['likeTimes2']);
$commentTimesArr	=	array($param['commentTimes1'],  $param['commentTimes2']);
$meFollowTimesArr	=	array($param['meFollowTimes1'], $param['meFollowTimes2']);
$followMeTimesArr	=	array($param['followMeTimes1'], $param['followMeTimes2']);

// page
$sort 		=   '&ordersc='.$param['ordersc'];
$op 		=	'&op=1';
$mpurl	   .= 	$userList['urls'].$sort.$op;
$pageurl 	= 	multi($start, $perpage, $mpurl);
$nextpurl 	= 	$pageurl['next'];
$prevpurl 	= 	$pageurl['prev'];
$mpurl 		= 	$pageurl['urls'];
$firstpurl  = 	$pageurl['first'];
$nowPage	=	$start/$perpage + 1;
$nowNum		=	$nowPage*$perpage;

//平均值
for ($i=0;$i<count($result);$i++)
{
	$total[] 	  =		$userList[$i][$param['orderby']];
}

$average = round(max_min_mean($total,0,0));

$perpages = array(
		$perpage => ' selected'
);

//函数
function max_min_mean($array, $n, $m){
	rsort($array);
	for($i=0; $i<$n; $i++){
		unset($array[$i]);
	}

	sort($array);
	for($i=0; $i<$m; $i++){
		unset($array[$i]);
	}

	$max_min_mean = mean($array);
	return $max_min_mean;
}

function mean($array){
	$sum = 0;
	foreach($array as $value){
		$sum += $value;
	}
	$lenght = count($array);
	$mean = $sum/$lenght;
	return $mean;
}
